<template>
	<view class="all">
		<!--标题-->
		<view class="title">欢迎来到解忧杂货店！</view>
		
		<!--图片-->
		<view class="img"></view>
		
		<!--微信登录-->
		<view class="wechat" @click="login">微信登录</view>
		
		<!--管理员登录-->
		<view class="employee" @click="empLogin">管理员登录</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		onLoad() {
			this.init()
		},
		methods:{
			init() {
				let user = uni.getStorageSync('user')
				console.log(user);
				if (user != null && user != '') {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}
			},
			login(){
				const that=this
				uni.login({ 
					"provider": "weixin",
					"onlyAuthorize": true, // 微信登录仅请求授权认证
					success: function(event) {
						const {code} = event
						that.$request.post("/mini/user/login",event.code).then(res=>{
							if(res.code==200){
								uni.setStorageSync('token', res.data.token)
								uni.setStorageSync('user', res.data.loginUser)
								uni.switchTab({
									url: '/pages/index/index',
								})
							}else{
								uni.showToast({
									title: res.msg,
									icon: 'error',
									duration: 2000
								})
							}
						})
					},
					fail: function (err) {
				        // 登录授权失败  
				        // err.code是错误码
						console.log(err)
				    }
				})
			},
			empLogin(){
				uni.navigateTo({
					url: '/pages/login/login'
				})
			}
			//测试
		}
	}
</script>

<style scoped>
.all{
	display: flex;
	 flex-direction: column;
}
.title{
	font-size: 50rpx;
	margin: 0 auto;
	margin-top: 50rpx;
}
.img{
	margin: 50rpx auto;
	width: 620rpx;
	height: 660rpx;
	opacity: 1;
	background: url(https://img.js.design/assets/img/6552d2c6eb009f7cc7c2de1b.jpg#c03d7d9c94c2a49e1d5f5cb574dc5248) no-repeat;
	background-size:cover;
}
.wechat{
	margin: 50rpx auto 0;
	height: 110rpx;
	width: 650rpx;
	text-align: center;
	line-height: 100rpx;
	background: rgba(0, 134, 118, 1);
	box-shadow: 0px 3px 12px  rgba(54, 139, 232, 0.24);
	border-radius: 25rpx;
	font-size: 38rpx;
	color: rgba(255, 255, 255, 1);
}
.employee{
	width: 120rpx;
	margin: 20rpx auto 0;
	text-align: center;
	font-size: 24rpx;
	color: #333;
}
</style>